<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<include file="Public/head" />
</head>

<body>
<include file="Public/top" />

<div class="page_minheight">
<div class="login_tit">用户登录</div>
<div class="page_in margin">
  <form action="{:U('User/do_login')}" method="post">
    <input type="hidden" name="referurl" id="referurl" value="{$referurl}">
    <div class="ginput_div ginput_div_icon"><i class="icon-yonghu"></i><input class="ginput" type="text" id="username" name="username"  onkeydown="if(event.keyCode==13){checkSubmit();}" placeholder="手机号/邮箱" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-mima"></i><input class="ginput" name="password" id="password" type="password" onKeyDown="if(event.keyCode==13){checkSubmit();}" placeholder="请输入密码" /></div>
    <div class="ginput_div ginput_div_icon"><i class="icon-yanzhengma2"></i><input class="ginput" onKeyDown="if(event.keyCode==13){checkSubmit();}" type="text" name="verify_code" id="verify_code" placeholder="请输入验证码" maxlength="4" /><span class="code"><img id="verify_code_img" src="{:U('Home/User/verify')}" onclick="verify(this)" /></span></div>
    <div class="ginput_div"><button type="button" class="login_sub" onClick="checkSubmit()">{$Think.lang.loginsubmit}</button></div>
    <div class="login_forgot">
      <p>     <a href="{:U('User/forget_pwd')}">忘记密码?</a>
        &nbsp; &nbsp; <a href="{:U('User/reg')}">注册账号</a>
              <!--&lt;!&ndash;<a href="{:U('LoginApi/wx_login',array('oauth'=>'weixin'))}">.</a>&ndash;&gt;-->
      </p>
    </div>
  </form>
</div><!--page_in-->
</div><!--page_minheight-->

<script>
function verify()
{
	$('#verify_code_img').attr('src','/index.php?m=Mobile&c=User&a=verify&r='+Math.random());
}

function checkSubmit()
{
	var username = $('#username').val();
	var password = $('#password').val();
	var referurl = $('#referurl').val();
	var verify_code = $('#verify_code').val();
	if(username == ''){
		layer.msg('用户名不匹配.');
		return false;
	}

	if(password == ''){
		layer.msg('密码不能为空');
		return false;
	}
	/*if(verify_code == ''){
		layer.alert('驗證碼不能為空', 800);
		return false;
	}*/

	$.ajax({
		type : 'post',
		//url : '/index.php?m=Home&c=User&a=do_login&t='+Math.random(),
		url : "{:U('User/do_login')}?t="+Math.random(),
		//   /index.php?m=Home&c=User&a=do_login&t='+Math.random(),
		data : {username:username,password:password,referurl:referurl,verify_code:verify_code},
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				window.location.href = res.url;
			}else{
				layer.msg(res.msg);
				verify();
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			//showErrorMsg('網絡失敗，請刷新頁面後重試');
			layer.msg('網絡失敗，請刷新頁面後重試');
		}
	})

}

function checkMobile(tel) {
	var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
	if (reg.test(tel)) {
		return true;
	}else{
		return false;
	};
}

function checkEmail(str){
	var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
	if(reg.test(str)){
		return true;
	}else{
		return false;
	}
}

function showErrorMsg(msg){
	alert(msg);
}
</script>

<include file="Public/footer" />
<script src="__STATIC__/js/global_after.js" type="text/javascript"></script>
</body>
</html>